/**
 * Copyright (c) 2007 lyxite.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Xml;
using System.Xml.Serialization;

namespace Weys.Lib
{
	/// <summary>
	/// skin of the application / capture dialog. XML serializable read & write.
	/// same as the the skin file name (without the extension ".xml").
	/// </summary>
	[XmlRootAttribute("Skin", Namespace="", IsNullable=false)]	
	public class Skin
	{
		/// <summary>
		/// name of skin, usually the named after the phone brand and model. no space
		/// </summary>
		public string Name;
		/// <summary>
		/// number of modes the skin has. 
		/// a phone may have different showing area on the screen in different modes
		/// </summary>
		public int ModeCount;
		/// <summary>
		/// the current working mode
		/// </summary>
		[XmlElementAttribute("DefaultMode")]
		public int Mode;
		
		/// <summary>
		/// indicates if the image is shared by the several skin pieces
		/// </summary>
		public bool IsImageShared;

		public bool IsTransparencyEnabled;

		public string Brand;
		//{	get { return "_";}	set {}}
		public string ModelName;
		//{get {return "_";}	set {}	}
		/// <summary>
		/// color that will not be displayed
		/// </summary>
		[XmlIgnoreAttribute()]
		public Color TransparencyColor;

		[XmlElementAttribute("TransparencyColor")]
		public string TransparencyColorRGB
		{
			get { return string.Format("{0,0:X08}", TransparencyColor.ToArgb());}
			set { TransparencyColor = Color.FromArgb(int.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier));}
		}
		/// <summary>
		/// each mode is corresponded to a skin piece
		/// </summary>
		[XmlArrayAttribute("Pieces")]
		public SkinPiece [] Pieces;

		/// <summary>
		/// the current active skin piece
		/// </summary>
		[XmlIgnoreAttribute()]
		public SkinPiece ActiveSkin
		{
			get 
			{
				if(Mode > 0 && IsImageShared)
				{
					Pieces[Mode].SkinImage = Pieces[0].SkinImage;
					Pieces[Mode].SkinSize = Pieces[0].SkinSize;
				}
				return Pieces[Mode]; 
			}
		}

		public Skin(){}
		public static Skin Load(string path)
		{
			ObjectXMLSerializer objectXMLSerializer = new ObjectXMLSerializer();
			Skin skin = new Skin();
			return (Skin) objectXMLSerializer.Load(skin, path);
		}
		public bool Save(string path)
		{			
			ObjectXMLSerializer objectXMLSerializer = new ObjectXMLSerializer();
			return objectXMLSerializer.Save(this, path);
		}
	}
}
